"""Example scripts for some 2D meshes"""

import meshpy.triangle as triangle
import meshpy_utils as util

# BOUNDARY CONDITION CONSTANTS TO IDENTIFY THE MESH
from grid import TransmissiveBoundary
from grid import Grid2D

# MeshType
from grid import MeshType

def shocktube2D(xl=-0.6, xr=0.6):
    """Generate a 2D mesh for the shocktube problem"""

    boundaryid = TransmissiveBoundary.id

    xmid = 0.5 * (xl + xr)
    points = [ (xl, 0.0), (xmid, 0), (xr, 0), (xr, 1), (xmid, 1), (xl, 1) ]
    #             0          1           2       3          4         5

    # generate the basic mesh and set the points
    info = triangle.MeshInfo()
    info.set_points(points)

    # Set the facets and markers.
    info.set_facets( facets=util.round_trip_connect( [0, 1, 4, 5] ) + \
                     util.round_trip_connect( [1, 2, 3, 4] ),

                     facet_markers=[ boundaryid, 0, boundaryid,
                                     boundaryid, boundaryid,
                                     boundaryid, boundaryid, 0]
                     )

    # set the two regions for the pre and post states
    info.regions.resize(2)
    info.regions[0] = ( 0.5 * (xl + xmid), 0.5, 0, 0.001 )
    info.regions[1] = ( 0.5 * (xmid + xr), 0.5, 1, 0.001 )

    # Generate the mesh
    mesh = triangle.build(info,
                          generate_faces=True,
                          verbose=False,
                          attributes=True,
                          volume_constraints=True,
                          quality_meshing=True)

    mesh.type = MeshType.MeshPy

    return Grid2D(mesh, 4)
